package HttpPages;

import java.util.Vector;
import java.util.logging.Level;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import Database.Database;
import Logger.AppLogger;
import Objects.UserProfile;

// POJO, no interface no extends

// The class registers its methods for the HTTP GET request using the @GET annotation. 
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML. 

// The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {

	// This method is called if TEXT_PLAIN is request
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	public String sayPlainTextHello() {
		System.out.println("requested TEXT_PLAIN");
		AppLogger.write(Level.INFO, "requested TEXT_PLAIN");
		return "Hello Jersey";
	}

	// This method is called if XML is request
	@GET
	@Produces(MediaType.TEXT_XML)
	public String sayXMLHello() {
		System.out.println("requested TEXT_XML");
		return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
	}

	// This method is called if HTML is request
	@GET
	@Produces(MediaType.TEXT_HTML)
	public String sayHtmlHello() {
		System.out.println("requested TEXT_HTML");
		return "<html> " + "<title>" + "Hello Jersey" + "</title>"
				+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
	}
	
	// This method is called if HTML is request
	@POST
	@Produces(MediaType.TEXT_HTML)
	public void getRegistrationID() {
		System.out.println();
	}

	@GET
	@Produces("application/xml")
	//@Produces(MediaType.TEXT_HTML)
	//public UserProfile getObjInXml(@FormParam("my_android_id") String my_android_id) {
	public Vector<UserProfile> getObjInXml() {
		System.out.println("requested APPLICATION_XML");
		return Database.getInstance().getAllUsers();
	}
}